package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class BiInitMain {
    public static void main(String[] args) {
        try {
            //factory
            ConnectionFactory connectionFactory = new ConnectionFactory();
            // connection
            Connection connection = connectionFactory.newConnection();
            // channel
            Channel channel = connection.createChannel();
            // exchangeDeclare
            String EXCHANGE_NAME = BiMqConstant.BI_EXCHANGE_NAME;
            channel.exchangeDeclare(EXCHANGE_NAME,"direct");
            // queueDeclare
            String QUEUE_NAME = BiMqConstant.BI_QUEUE_NAME;
            // 设置 持久化、非独占、非自动删除、传入参数
            channel.queueDeclare(QUEUE_NAME,true,false,false,null);
            // queueBind
            channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,BiMqConstant.BI_ROUTING_KEY);
        } catch (IOException | TimeoutException e) {
            e.printStackTrace();
        }
    }
}
